<?php
/*
	我的下线
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
set_html('title','我的团队');
if($_RQ['op']=='main'){
	set_html('tabs','我的团队');
	$setting=$this->plugin_setting('setting');
	$levelnum=2;
	$agent_num=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'fromuser'=>$_SESSION['uid']),'id');
	$levels=array();
	for($i=0;$i<$levelnum;$i++){
		$level=$i+1;
		if($i==0){
			$levels[$level]['title']='直推用户';
			$levels[$level]['num']=pdo_count('core_members',array('fromuser'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
		}elseif($i==1){
			$levels[$level]['title']='间推用户';
			$mids=pdo_getall('core_members',array('fromuser'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id'),'id');
			if($mids){
				$mids=array_keys($mids);
			}else{
				$mids=-1;
			}
			$levels[$level]['num']=pdo_count('core_members',array('fromuser'=>$mids,'uniacid'=>$_SESSION['uniacid']),'id');
			$agent_num +=$levels[$level]['num'];
		}
	}
	$return['levels']=$levels;
	$return['agent_num']=$agent_num;
	$return['member']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['params']=array('page'=>1,'level'=>1);
	$return['psize']=20;
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$level=intval($_RQ['level'])?:1;
	if($level==1){
		$params['fromuser']=$_SESSION['uid'];
	}elseif($level==2){
		$mids=pdo_getall('core_members',array('fromuser'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id'),'id');
		if($mids){
			$mids=array_keys($mids);
		}else{
			$mids=-1;
		}
		$params['fromuser']=$mids;
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>array('id','nickname','avatar','createtime','fromuser')
	);
	$list=pdo_getlist('core_members',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['member_num']=pdo_count('core_members',array('uniacid'=>$_SESSION['uniacid'],'fromuser'=>$item['id']));
		$item['ordercount']=pdo_count('jy_merch_game_commission_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['id']));
		$item['moneycount']=pdo_getsum('jy_merch_game_commission_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['id']),'order_price');
	}
	exi($list);
}
?>